import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TilePanel } from "../equipment/TilePanel";
import { ArenaCorssToplistRenderer } from "./ArenaCorssToplistRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { Cache } from "../../cache/Cache";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { SArenaCrossToplists } from "../../../../Message/Public/SArenaCrossToplists";
import { _page } from "../../../../this/_page";
import { _pageSize } from "../../../../this/_pageSize";
type int = number;
//class KingWarListPanel
    
    export  class KingWarListPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 804, 445, this);
            ObjCreate.createBg(1, -2, 804, 30, this, ImagesConst.RbListHeader);
            ObjCreate.createTextField(Language.getString(36180), 20, 5, 30, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36181), 120, 5, 100, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36182), 265, 5, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36183), 360, 5, 30, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36184), 425, 5, 30, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36185), 510, 5, 30, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36186), 598, 5, 60, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36187), 700, 5, 80, 20, this, GlobalStyle.textFormat6);
            this._tilePanel = new TilePanel();
            this._tilePanel.horizontalGap = 0;
            this._tilePanel.verticalGap = 0;
            this._tilePanel.columnWidth = 804;
            this._tilePanel.rowHeight = 42;
            this._tilePanel.rowCount = 10;
            this._tilePanel.setSize(804, 420);
            this._tilePanel.setStyle("cellRenderer", ArenaCorssToplistRenderer);
            this._tilePanel.move(0, 25);
            addChild(this._tilePanel);
            this._pagebar = new PageSelecter();
            this._pagebar.mode = PageSelecter.CompleteMode;
            this._pagebar.move(300, 455);
            this._pagebar.currentPage = 1;
            this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            addChild(this._pagebar);
            this._pageInput = ObjCreate.createGTextInput(440, 455, 40, 20, this);
            var loc1=ObjCreate.createTextField("", 490, 455, 30, 20, this);
            loc1.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(32051) + "</u><a>";
            loc1.addEventListener(flash.events.TextEvent.LINK, this.onSkipPageLinkHandler);
            addChild(loc1);
            return;
        }

        public updateInfo(): void
        {
            this._sArenaCrossToplists = Cache.instance.kingwar.sArenaCrossToplists;
            if (this._sArenaCrossToplists == null) 
            {
                return;
            }
            this._pagebar.maxPage = this._sArenaCrossToplists.pageNum;
            this._tilePanel.dataProvider = new DataProvider(this._sArenaCrossToplists.toplists);
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            this.sendPageChange();
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._page = this._pagebar.currentPage;
            this.sendPageChange();
            return;
        }

        /* internal  */onSkipPageLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=parseInt(this._pageInput.text);
            if (loc1 > 0 && loc1 <= this._pagebar.maxPage) 
            {
                this._page = loc1;
                this._pagebar.currentPage = this._page;
                this.sendPageChange();
            }
            return;
        }

        /* internal  */sendPageChange(): void
        {
            var loc1={"process": 0, "onlyMyServer": false, "page": _page, "pageSize": _pageSize};
            Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarGetToplist, loc1));
            return;
        }

        /* internal */ /* var */_tilePanel: TilePanel;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_pageInput: GTextInput;

        /* internal */ /* var */_page: int=1;

        /* internal */ /* var */_pageSize: int=10;

        /* internal */ /* var */_sArenaCrossToplists: SArenaCrossToplists;
    }
